﻿using System;
using System.Windows.Forms;

namespace Lap
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string[] A = textBox1.Text.Split(',', '，');
            string[] B = textBox2.Text.Split(',', '，');
            double ACNorm = double.Parse(textBox3.Text.ToString());
            double L = double.Parse(textBox4.Text.ToString());
            double d = double.Parse(textBox5.Text.ToString());
            if (A.Length != 2 || B.Length != 2)
            {
                MessageBox.Show("坐标格式错误，请重新输入坐标！！");
            }
            Utils.Point pointA = new Utils.Point(double.Parse(A[0]), double.Parse(A[1]));
            Utils.Point pointB = new Utils.Point(double.Parse(B[0]), double.Parse(B[1]));
            Vector vectorAB = new Vector(pointB.X - pointA.X, pointB.Y - pointA.Y);
            Utils.Point pointC = new Utils.Point();
            pointC.X = pointA.X + ACNorm * (vectorAB.X / Vector.Norm(vectorAB.X, vectorAB.Y));
            pointC.Y = pointA.Y + ACNorm * (vectorAB.Y / Vector.Norm(vectorAB.X, vectorAB.Y));
            Vector vectorAC = new Vector(pointC.X - pointA.X, pointC.Y - pointA.Y);
            Vector vectorCB = new Vector(pointB.X - pointC.X, pointB.Y - pointC.Y);
            Utils.Point pointD = new Utils.Point();
            pointD.X = pointC.X - (2 / L) * (vectorAC.X / Vector.Norm(vectorAC.X, vectorAC.Y));
            pointD.Y = pointC.Y - (2 / L) * (vectorAC.Y / Vector.Norm(vectorAC.X, vectorAC.Y));
            Utils.Point pointF = new Utils.Point();
            pointF.X = pointC.X + (2 / L) * (vectorCB.X / Vector.Norm(vectorCB.X, vectorCB.Y));
            pointF.Y = pointC.Y + (2 / L) * (vectorCB.Y / Vector.Norm(vectorCB.X, vectorCB.Y));
            double Angle = Math.Atan(d / L * 180 / Math.PI);
            Class1.Rotation(pointD, pointB, L, Angle);
            double NegativeAngle = -Math.Atan(d / L * 180 / Math.PI);
            Class1.Rotation(pointA, pointF, L, NegativeAngle);
        }
    }
}
